#!/usr/bin/env python

# Imports:
# -------
import wx

# -----------------------------
class AnnotationPanel(wx.Panel):
# -----------------------------
	# ------------------------
	def __init__(self, parent):
	# ------------------------
		wx.Panel.__init__(self, parent=parent)

		# Create the sizer
		self.sizer = wx.BoxSizer(wx.VERTICAL)
		self.SetSizer(self.sizer)

		# Add the label
		self.annotationLabel = wx.StaticText(self, label='Annotations:')
		self.annotationLabel.Disable()
		self.sizer.Add(self.annotationLabel, 0, wx.CENTER)

		# Add the listbox
		self.listBox = wx.ListBox(self, -1, (-1,-1), (-1,-1), [], wx.LB_SINGLE)
		self.listBox.Disable()
		self.sizer.Add(self.listBox, 1, wx.EXPAND)
		self.sizer.AddSpacer(10)

		# Add the buttons 
		self.newButton = wx.Button(self, wx.ID_ANY, '&New Annotation')
		self.newButton.Disable()
		self.sizer.Add(self.newButton, 0, wx.CENTER | wx.EXPAND)
		self.sizer.AddSpacer(5)
		self.deleteButton = wx.Button(self, wx.ID_ANY, '&Delete Annotation')
		self.deleteButton.Disable()
		self.sizer.Add(self.deleteButton, 0, wx.CENTER | wx.EXPAND)

		self.sizer.AddSpacer(10)

		# Update the layout	
		self.Layout()

	# --------------
	def Enable(self):
	# --------------
		self.annotationLabel.Enable()
		self.listBox.Enable()
		self.deleteButton.Enable()
		self.newButton.Enable()

	# ---------------
	def Disable(self):
	# ---------------
		self.annotationLabel.Enable()
		self.listBox.Enable()
		self.deleteButton.Enable()
		self.newButton.Enable()

	# -----------------------------------------------
	def showAnnotations(self, annotationArray, i = 0):
	# -----------------------------------------------
		annotations = [annotation.name for annotation in annotationArray.annotations]
		self.listBox.Set(annotations)

		if len(annotations) > 0:
				self.listBox.SetSelection(i)
				return annotations[i], annotationArray.annotations[i].orientation
		else:
				return '', ''

	# -------------------------
	def getSelectionIndex(self):
	# ------------------------
		iTup = self.listBox.GetSelections()
		return iTup[0] if len(iTup) > 0 else -1
